package com.pet.shop.entity.option;

import java.io.Serializable;
import java.util.Date;

/**
 * Created by candy.zhao on 2016-11-8.
 */
public class DataOptionView implements Serializable, Comparable<DataOptionView> {

    private static final long serialVersionUID = 3375675452367066159L;

    private Long id;
    private Long dataOptionId;  //数据选项编号
    private String dataName;    //选项名称
    private String dataKey;     //选项关键词
    private Integer dataType;   //选项分组类型
    private Long dependId;      //该属性依赖的id
    private Integer sort;       //选项排序
    private String remark;      //选项备注
    private Long userId;
    private String value;       //选项
    private Date createTime;    //创建时间
    private Long creatorId;     //创建人
    private Date modifyTime;    //修改时间
    private Long modifierId;    //修改人

    public DataOptionView() {
    }

    public DataOptionView(DataOption option) {
        this.dataOptionId = option.getId();
        this.dataName = option.getDataName();
        this.dataKey = option.getDataKey();
        this.dataType = option.getDataType();
        this.value = option.getDefaultValue();
        this.sort = option.getSort();
        this.dependId = option.getDependId();
        this.remark = option.getRemark();
    }

    public void updateVal(DataOptionVal val){
        if(val == null) return;
        this.id = val.getId();
        this.userId = val.getUserId();
        if(val.getValue() != null && !"".equals(val.getValue().trim())) this.value = val.getValue();
        this.createTime = val.getCreateTime();
        this.creatorId = val.getCreatorId();
        this.modifyTime = val.getModifyTime();
        this.modifierId = val.getModifierId();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getDataOptionId() {
        return dataOptionId;
    }

    public void setDataOptionId(Long dataOptionId) {
        this.dataOptionId = dataOptionId;
    }

    public String getDataName() {
        return dataName;
    }

    public void setDataName(String dataName) {
        this.dataName = dataName;
    }

    public String getDataKey() {
        return dataKey;
    }

    public void setDataKey(String dataKey) {
        this.dataKey = dataKey;
    }

    public Integer getDataType() {
        return dataType;
    }

    public void setDataType(Integer dataType) {
        this.dataType = dataType;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Long getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(Long creatorId) {
        this.creatorId = creatorId;
    }

    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public Long getModifierId() {
        return modifierId;
    }

    public void setModifierId(Long modifierId) {
        this.modifierId = modifierId;
    }

    public Long getDependId() {
        return dependId;
    }

    public void setDependId(Long dependId) {
        this.dependId = dependId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("DataOptionDTO{");
        sb.append("id=").append(id);
        sb.append(", dataOptionId=").append(dataOptionId);
        sb.append(", dataName='").append(dataName).append('\'');
        sb.append(", dataKey='").append(dataKey).append('\'');
        sb.append(", dataType=").append(dataType);
        sb.append(", dependId=").append(dependId);
        sb.append(", sort=").append(sort);
        sb.append(", remark='").append(remark).append('\'');
        sb.append(", value='").append(value).append('\'');
        sb.append(", createTime=").append(createTime);
        sb.append(", creatorId=").append(creatorId);
        sb.append(", modifyTime=").append(modifyTime);
        sb.append(", modifierId=").append(modifierId);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public int compareTo(DataOptionView o) {
        if(o == null) return -1;
        try{
            Integer v1 = Integer.parseInt(getValue());
            Integer v2 = Integer.parseInt(o.getValue());
            if(v1 < v2) return 1;
            if(v1 > v2) return -1;
        }catch (Exception e){
            return 0;
        }
        return 0;
    }
}
